
cc.Class({
    extends: cc.Component,

    properties: {
   
        sprArray :{
            default:[],
            type:[cc.SpriteFrame],
        },
        firstdigit:cc.Node,
        seconddigit:cc.Node,
        threedigit:cc.Node


    },

  

    onLoad () {

         
     
    

    },


    init(coinNumber){

        var number = coinNumber
        console.log("红包数",coinNumber)
        number = number.toString() //把数字转换成字符串
        if(number.length==1){

            number="00"+number
        }else if(number.length==2){
            number="0"+number
        }else{

            console.log("刚好三位不做处理")
        }
        for (var i = 0; i < number.length; i++) {
        
           if(i==0){
               this.firstdigit.getComponent(cc.Sprite).spriteFrame=this.sprArray[number[0]]
               this.firstdigit.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
               this.firstdigit.getComponent(cc.Sprite).type = cc.Sprite.Type.SIMPLE;
               let rect =this.sprArray[number[0]].getRect();//获取节点的轮扩
               console.log("个位数图片宽度",rect.width)
               this.firstdigit.width = rect.width/2
             
           }else if(i==1){
               this.seconddigit.getComponent(cc.Sprite).spriteFrame=this.sprArray[number[1]]  
               this.seconddigit.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
               this.seconddigit.getComponent(cc.Sprite).type = cc.Sprite.Type.SIMPLE;
               let rect =this.sprArray[number[1]].getRect();//获取节点的轮扩
               console.log("小数第一位图片宽度",rect.width)
               this.seconddigit.width = rect.width/2


           }else{
               this.threedigit.getComponent(cc.Sprite).spriteFrame=this.sprArray[number[2]]
               this.threedigit.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
               this.threedigit.getComponent(cc.Sprite).type = cc.Sprite.Type.SIMPLE;
               let rect =this.sprArray[number[2]].getRect();//获取节点的轮扩
               console.log("小数第2位图片宽度",rect.width)
               this.threedigit.width = rect.width/2
           
           }

       }

    },

    start () {

    },

    // update (dt) {},
});
